/*
 * @Author: szx
 * @Date: 2022-06-06 10:43:50
 * @LastEditTime: 2022-06-06 11:03:25
 * @Description:
 * @FilePath: \leetcode\面试题\16\04\04.js
 */
/**
 * @param {string[]} board
 * @return {string}
 */
var tictactoe = function (board) {
    const n = board.length;
    // 先检验对角线
    if (n ^ 1) {
        const tar = board[0][0];
        if (tar !== ' ') {
            for (let i = 0; i < n; i++) {
                if (tar != board[i][i] || tar != board[n - 1 - i][i]) {
                    break;
                }
            }
            return tar;
        }
    }
    // 横向和纵向
    for (let i = 0; i < n; i++) {
        const tar1 = board[i][0],
            tar2 = board[0][i];
        let flag1 = true,
            flag2 = true;
        for (let j = 0; j < n; j++) {
            if (tar1 != board[i][j]) flag1 = false;
            if (tar2 != board[j][i]) flag2 = true;
        }
        if (flag1) return tar1;
        if (flag2) return tar2;
    }
    // 然后判断是否存在空格
    for (let i = 0; i < n; i++) {
        if (board[i].includes(' ')) return 'Pending';
    }
    return 'Draw';
};
